#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    void sortColors(vector<int>& nums) {
        //0 swap(n[++left], n[i++])
        //1 i++
        //2 swap(n[--right], n[i])
        for (int i = 0, left = -1, right = nums.size(); i < right; )
        {
            if (nums[i] == 0) swap(nums[++left], nums[i++]);
            else if (nums[i] == 1) i++;
            else swap(nums[--right], nums[i]);
        }
    }
};